package com.hc.springboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hc.springboot.entity.UserEntity;
import com.hc.springboot.enums.UserSexEnum;

public interface UserMapper {

	@Select("SELECT * FROM users")
	@Results({
		@Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),
		@Result(property = "nickname", column = "nick_name")
	})
	List<UserEntity> getAll();
	
	@Select("SELECT * FROM users WHERE id = #{id}")
	@Results({
		@Result(property = "userSex", column = "user_sex", javaType = UserSexEnum.class),
		@Result(property = "nickname", column = "nick_name")
	})
	UserEntity getOne(Long id);
	
	@Insert("INSERT INTO users(id, username, password, user_sex) VALUES (seq_users.nextval, #{username}, #{password}, #{userSex})")
	void insert(UserEntity user);
	
	@Update("UPDATE users SET username=#{username}, nick_name=#{nickname} WHERE id=#{id}")
	void update(UserEntity user);
	
	@Delete("DELETE FROM users WHERE id=#{id}")
	void delete(Long id);
}
